<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {


    public function _initialize()
    {
        //添加权限处理
    }

    /**
     * 列表 处理 公共
     * @return [type] [description]
     */
    public function lists()
    {
        $M=D(CONTROLLER_NAME);
        $map=array(
            'status'=>array('egt',0),
            'is_delete'=>0
        );
        $count=$M->countMap($map);
        $page=new \Think\Page($count,10);

        $Ms=$M->listMap($map,$page->firstRow.','.$page->listRows);


        $this->assign('Ms',$Ms);
        $this->assign('page',$page->show());

        $this->display();
    }
    /**
     * 修改 公共
     * @return [type] [description]
     */
    public function edit()
    {
        $id = I('get.id',0,'intval');
        if (IS_POST && I('post.id',0,'intval')) {
            $M=D(CONTROLLER_NAME,'Logic');
            $M->create(I('post.'),2);
            if (!is_null($M) && !$M->getError()) {
                $M->save();
                $this->success('修改成功！');
            } else {
                $this->error($M->getError());
            }
        } else {
            $M=M(CONTROLLER_NAME)->where(array('id'=>$id))->find();
            $classes=M('class')->where(array('status'=>array('egt',0),'is_delete'=>0))->select();
            $this->assign('classes',$classes);
            $this->assign('M',$M);
            $this->display();
        }
        
    }
    /**
     * 添加数据 公共
     */
    public function add()
    {
        $M = D(CONTROLLER_NAME);
        if (IS_POST) {
            if ($M->create() && !$M->getError()) {
                if ($M->add()) {
                    $this->success('添加成功！');
                } else {
                    $this->error($M->getError());
                }
            } else {
                $this->error($M->getError());
            }
        } else {
            $this->display();
        }
    }
    /**
     * 软删除 公共
     * @return [type] [description]
     */
    public function delete()
    {
        $id = I('id',0,'intval');
        $M=M(CONTROLLER_NAME);
        if ($M->where(array('id'=>$id,'is_delete'=>0))->setField('is_delete',1)) {
            $this->success('删除成功！');
        } else {
            $this->error('删除失败！！！！');
        }
    }
}